using DG.Tweening;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UISkinNotification : MonoBehaviour
{
	[Serializable]
	public class EditorReferences
	{
		public RectTransform notificationTransform;

		[Header("Skin")]
		public GameObject normalNotif;

		public Image skinIcon;

		public Text unlockTitleText;

		public Text unlockConditionText;

		public Transform unlockCheckTransform;

		[Header("Animal")]
		public GameObject animalNotif;

		public Image animalImage;

		public Text animalNameText;
	}

	public abstract class NotificationContent
	{
	}

	public class NotificationContentUnlock : NotificationContent
	{
		public SkinParameters skinParameters;

		public NotificationContentUnlock(SkinParameters parameters)
		{
			skinParameters = parameters;
		}
	}

	public class NotificationContentBuy : NotificationContent
	{
		public SkinParameters skinParameters;

		public NotificationContentBuy(SkinParameters parameters)
		{
			skinParameters = parameters;
		}
	}

	public class NotificationContentAnimal : NotificationContent
	{
		public string animalName;

		public float unlockRatio;

		public NotificationContentAnimal(string name, float ratio)
		{
			animalName = name;
			unlockRatio = ratio;
		}
	}

	public static UISkinNotification Instance;

	[SerializeField]
	public EditorReferences references = new EditorReferences();

	private bool _isShowingNotification;

	private static List<NotificationContent> _pendingNotifications = new List<NotificationContent>();

	private void Awake()
	{
		Instance = this;
	}

	private void Start()
	{
		references.notificationTransform.gameObject.SetActive(value: false);
		CheckPendingNotifications();
	}

	public void CheckPendingNotifications()
	{
		if (_pendingNotifications.Count > 0)
		{
			ShowNotification(_pendingNotifications[0]);
			_pendingNotifications.RemoveAt(0);
		}
	}

	public void ShowNotification(NotificationContent content)
	{
		if (_isShowingNotification)
		{
			_pendingNotifications.Add(content);
			return;
		}
		if (content is NotificationContentUnlock)
		{
			SetUnlockContent(content as NotificationContentUnlock);
		}
		else if (content is NotificationContentBuy)
		{
			SetBuyContent(content as NotificationContentBuy);
		}
		else if (content is NotificationContentAnimal)
		{
			SetAnimalContent(content as NotificationContentAnimal);
		}
		Show();
	}

	private void SetUnlockContent(NotificationContentUnlock content)
	{
		SkinParameters skinParameters = content.skinParameters;
		references.normalNotif.SetActive(value: true);
		references.animalNotif.SetActive(value: false);
		references.unlockCheckTransform.localScale = Vector3.zero;
		references.skinIcon.sprite = skinParameters.skinIcon;
		references.unlockTitleText.color = skinParameters.mainColor;
		Achievement achievementForSkin = AchievementManager.Instance.GetAchievementForSkin(skinParameters.skinIndex);
		references.unlockConditionText.text = achievementForSkin.GetDescription();
	}

	private void SetBuyContent(NotificationContentBuy content)
	{
		SkinParameters skinParameters = content.skinParameters;
		references.normalNotif.SetActive(value: true);
		references.animalNotif.SetActive(value: false);
		references.unlockCheckTransform.localScale = Vector3.zero;
		references.skinIcon.sprite = skinParameters.skinIcon;
		references.unlockTitleText.color = skinParameters.mainColor;
		references.unlockConditionText.text = "Thank you for your purchase!";
	}

	private void SetAnimalContent(NotificationContentAnimal content)
	{
		references.normalNotif.SetActive(value: false);
		references.animalNotif.SetActive(value: true);
		references.animalImage.fillAmount = content.unlockRatio;
		references.animalNameText.text = string.Format(LocalizationManager.GetTranslation("TXT_SKIN_ZOO_ESCAPE_CAPTURE"), LocalizationManager.GetTranslation(content.animalName));
	}

	private void Show()
	{
		references.notificationTransform.gameObject.SetActive(value: true);
		_isShowingNotification = true;
		references.notificationTransform.anchoredPosition = new Vector2(0f, 300f);
		Sequence s = DOTween.Sequence();
		s.Append(references.notificationTransform.DOAnchorPosY(100f, 0.5f).SetEase(Ease.OutBack)).AppendInterval(0.3f).Append(references.unlockCheckTransform.DOScale(1f, 0.2f).SetEase(Ease.OutBack))
			.AppendInterval(1.5f)
			.Append(references.notificationTransform.DOAnchorPosY(300f, 0.3f).SetEase(Ease.InBack))
			.OnComplete(delegate
			{
				_isShowingNotification = false;
				references.notificationTransform.gameObject.SetActive(value: false);
				CheckPendingNotifications();
			});
	}
}
